package com.liuxvru.project.user.controller;

import com.liuxvru.common.annotation.Log;
import com.liuxvru.common.core.controller.BaseController;
import com.liuxvru.common.core.domain.AjaxResult;
import com.liuxvru.common.core.page.TableDataInfo;
import com.liuxvru.common.enums.BusinessType;
import com.liuxvru.common.utils.poi.ExcelUtil;
import com.liuxvru.project.domain.WorkDependency;
import com.liuxvru.project.service.IWorkDependencyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 工作项依赖Controller
 *
 * @author liuxvru
 * @date 2024-11-22
 */
@RestController
@RequestMapping("/user/project/workDependency")
public class UserWorkDependencyController extends BaseController {
    @Autowired
    private IWorkDependencyService workDependencyService;

    /**
     * 查询工作项依赖列表
     */
    @PreAuthorize("@ss.hasPermi('project:workDependency:list')")
    @GetMapping("/list/{projectId}")
    public TableDataInfo list(@PathVariable("projectId") Long projectId, WorkDependency workDependency) {
        startPage();
        List<WorkDependency> list = workDependencyService.selectWorkDependencyList(workDependency);
        return getDataTable(list);
    }

    /**
     * 查询工作项依赖列表
     */
    @PreAuthorize("@ss.hasPermi('project:workDependency:list')")
    @GetMapping("/listAll/{projectId}")
    public AjaxResult listAll(@PathVariable("projectId") Long projectId, WorkDependency workDependency) {
        List<WorkDependency> list = workDependencyService.selectWorkDependencyList(workDependency);
        return success(list);
    }

    /**
     * 导出工作项依赖列表
     */
    @PreAuthorize("@ss.hasPermi('project:workDependency:export')")
    @Log(title = "工作项依赖", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WorkDependency workDependency) {
        List<WorkDependency> list = workDependencyService.selectWorkDependencyList(workDependency);
        ExcelUtil<WorkDependency> util = new ExcelUtil<WorkDependency>(WorkDependency.class);
        util.exportExcel(response, list, "工作项依赖数据");
    }

    /**
     * 获取工作项依赖详细信息
     */
    @PreAuthorize("@ss.hasPermi('project:workDependency:query')")
    @GetMapping(value = "/{dependencyId}")
    public AjaxResult getInfo(@PathVariable("dependencyId") Long dependencyId) {
        return success(workDependencyService.getById(dependencyId));
    }

    /**
     * 新增工作项依赖
     */
    @PreAuthorize("@ss.hasPermi('project:workDependency:add')")
    @Log(title = "工作项依赖", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WorkDependency workDependency) {
        return toAjax(workDependencyService.save(workDependency));
    }

    /**
     * 修改工作项依赖
     */
    @PreAuthorize("@ss.hasPermi('project:workDependency:edit')")
    @Log(title = "工作项依赖", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WorkDependency workDependency) {
        return toAjax(workDependencyService.updateById(workDependency));
    }

    /**
     * 删除工作项依赖
     */
    @PreAuthorize("@ss.hasPermi('project:workDependency:remove')")
    @Log(title = "工作项依赖", businessType = BusinessType.DELETE)
    @DeleteMapping("/{dependencyIds}")
    public AjaxResult remove(@PathVariable Long[] dependencyIds) {
        return toAjax(workDependencyService.removeById(dependencyIds));
    }
}
